package com.onevcat.UniPasteBoard;

import android.annotation.*;
import android.util.*;
import com.unity3d.player.*;
import android.app.*;
import android.os.*;
import android.text.*;
import android.content.*;

class PasteBoard
{
    private static CharSequence result;

    static {
        PasteBoard.result = "";
    }

    @SuppressLint({ "NewApi" })
    public static CharSequence coerceToText(final Context p0, final ClipData.Item p1) {
        //
        // This method could not be decompiled.
        //
        // Original Bytecode:
        //
        //     1: invokevirtual   android/content/ClipData$Item.getText:()Ljava/lang/CharSequence;
        //     4: astore_3
        //     5: aload_3
        //     6: ifnull          11
        //     9: aload_3
        //    10: areturn
        //    11: aload_1
        //    12: invokevirtual   android/content/ClipData$Item.getUri:()Landroid/net/Uri;
        //    15: astore          5
        //    17: aload           5
        //    19: ifnull          220
        //    22: aconst_null
        //    23: astore_3
        //    24: aconst_null
        //    25: astore          4
        //    27: aconst_null
        //    28: astore_1
        //    29: aload_0
        //    30: invokevirtual   android/content/Context.getContentResolver:()Landroid/content/ContentResolver;
        //    33: aload           5
        //    35: ldc             "text/*"
        //    37: aconst_null
        //    38: invokevirtual   android/content/ContentResolver.openTypedAssetFileDescriptor:(Landroid/net/Uri;Ljava/lang/String;Landroid/os/Bundle;)Landroid/content/res/AssetFileDescriptor;
        //    41: invokevirtual   android/content/res/AssetFileDescriptor.createInputStream:()Ljava/io/FileInputStream;
        //    44: astore_0
        //    45: aload_0
        //    46: astore_1
        //    47: aload_0
        //    48: astore_3
        //    49: aload_0
        //    50: astore          4
        //    52: new             Ljava/io/InputStreamReader;
        //    55: dup
        //    56: aload_0
        //    57: ldc             "UTF-8"
        //    59: invokespecial   java/io/InputStreamReader.<init>:(Ljava/io/InputStream;Ljava/lang/String;)V
        //    62: astore          6
        //    64: aload_0
        //    65: astore_1
        //    66: aload_0
        //    67: astore_3
        //    68: aload_0
        //    69: astore          4
        //    71: new             Ljava/lang/StringBuilder;
        //    74: dup
        //    75: sipush          128
        //    78: invokespecial   java/lang/StringBuilder.<init>:(I)V
        //    81: astore          7
        //    83: aload_0
        //    84: astore_1
        //    85: aload_0
        //    86: astore_3
        //    87: aload_0
        //    88: astore          4
        //    90: sipush          8192
        //    93: newarray        C
        //    95: astore          8
        //    97: aload_0
        //    98: astore_1
        //    99: aload_0
        //   100: astore_3
        //   101: aload_0
        //   102: astore          4
        //   104: aload           6
        //   106: aload           8
        //   108: invokevirtual   java/io/InputStreamReader.read:([C)I
        //   111: istore_2
        //   112: iload_2
        //   113: ifle            136
        //   116: aload_0
        //   117: astore_1
        //   118: aload_0
        //   119: astore_3
        //   120: aload_0
        //   121: astore          4
        //   123: aload           7
        //   125: aload           8
        //   127: iconst_0
        //   128: iload_2
        //   129: invokevirtual   java/lang/StringBuilder.append:([CII)Ljava/lang/StringBuilder;
        //   132: pop
        //   133: goto            97
        //   136: aload_0
        //   137: astore_1
        //   138: aload_0
        //   139: astore_3
        //   140: aload_0
        //   141: astore          4
        //   143: aload           7
        //   145: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
        //   148: astore          6
        //   150: aload_0
        //   151: ifnull          158
        //   154: aload_0
        //   155: invokevirtual   java/io/FileInputStream.close:()V
        //   158: aload           6
        //   160: areturn
        //   161: astore_0
        //   162: goto            194
        //   165: astore_0
        //   166: aload_3
        //   167: astore_1
        //   168: ldc             "ClippedData"
        //   170: ldc             "Failure loading text"
        //   172: aload_0
        //   173: invokestatic    android/util/Log.w:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
        //   176: pop
        //   177: aload_3
        //   178: astore_1
        //   179: aload_0
        //   180: invokevirtual   java/io/IOException.toString:()Ljava/lang/String;
        //   183: astore_0
        //   184: aload_3
        //   185: ifnull          192
        //   188: aload_3
        //   189: invokevirtual   java/io/FileInputStream.close:()V
        //   192: aload_0
        //   193: areturn
        //   194: aload_1
        //   195: ifnull          202
        //   198: aload_1
        //   199: invokevirtual   java/io/FileInputStream.close:()V
        //   202: aload_0
        //   203: athrow
        //   204: aload           4
        //   206: ifnull          214
        //   209: aload           4
        //   211: invokevirtual   java/io/FileInputStream.close:()V
        //   214: aload           5
        //   216: invokevirtual   android/net/Uri.toString:()Ljava/lang/String;
        //   219: areturn
        //   220: aload_1
        //   221: invokevirtual   android/content/ClipData$Item.getIntent:()Landroid/content/Intent;
        //   224: astore_0
        //   225: aload_0
        //   226: ifnull          235
        //   229: aload_0
        //   230: iconst_1
        //   231: invokevirtual   android/content/Intent.toUri:(I)Ljava/lang/String;
        //   234: areturn
        //   235: ldc             ""
        //   237: areturn
        //   238: astore_0
        //   239: goto            204
        //   242: astore_0
        //   243: aload           6
        //   245: areturn
        //   246: astore_1
        //   247: aload_0
        //   248: areturn
        //   249: astore_1
        //   250: goto            202
        //   253: astore_0
        //   254: goto            214
        //    Exceptions:
        //  Try           Handler
        //  Start  End    Start  End    Type
        //  -----  -----  -----  -----  -------------------------------
        //  29     45     238    257    Ljava/io/FileNotFoundException;
        //  29     45     165    194    Ljava/io/IOException;
        //  29     45     161    204    Any
        //  52     64     238    257    Ljava/io/FileNotFoundException;
        //  52     64     165    194    Ljava/io/IOException;
        //  52     64     161    204    Any
        //  71     83     238    257    Ljava/io/FileNotFoundException;
        //  71     83     165    194    Ljava/io/IOException;
        //  71     83     161    204    Any
        //  90     97     238    257    Ljava/io/FileNotFoundException;
        //  90     97     165    194    Ljava/io/IOException;
        //  90     97     161    204    Any
        //  104    112    238    257    Ljava/io/FileNotFoundException;
        //  104    112    165    194    Ljava/io/IOException;
        //  104    112    161    204    Any
        //  123    133    238    257    Ljava/io/FileNotFoundException;
        //  123    133    165    194    Ljava/io/IOException;
        //  123    133    161    204    Any
        //  143    150    238    257    Ljava/io/FileNotFoundException;
        //  143    150    165    194    Ljava/io/IOException;
        //  143    150    161    204    Any
        //  154    158    242    246    Ljava/io/IOException;
        //  168    177    161    204    Any
        //  179    184    161    204    Any
        //  188    192    246    249    Ljava/io/IOException;
        //  198    202    249    253    Ljava/io/IOException;
        //  209    214    253    257    Ljava/io/IOException;
        //
        // The error that occurred was:
        //
        // java.lang.IndexOutOfBoundsException: Index: 155, Size: 155
        //     at java.util.ArrayList.rangeCheck(ArrayList.java:657)
        //     at java.util.ArrayList.get(ArrayList.java:433)
        //     at com.strobel.decompiler.ast.AstBuilder.convertToAst(AstBuilder.java:3321)
        //     at com.strobel.decompiler.ast.AstBuilder.build(AstBuilder.java:113)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:211)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:782)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:675)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:552)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:519)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:161)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:150)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:125)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.buildAst(JavaLanguage.java:71)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.decompileType(JavaLanguage.java:59)
        //     at us.deathmarine.luyten.DecompilerLinkProvider.generateContent(DecompilerLinkProvider.java:97)
        //     at us.deathmarine.luyten.OpenFile.decompileWithNavigationLinks(OpenFile.java:494)
        //     at us.deathmarine.luyten.OpenFile.decompile(OpenFile.java:467)
        //     at us.deathmarine.luyten.Model.extractClassToTextPane(Model.java:420)
        //     at us.deathmarine.luyten.Model.openEntryByTreePath(Model.java:339)
        //     at us.deathmarine.luyten.Model$TreeListener$1.run(Model.java:266)
        //
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }

    @SuppressLint({ "NewApi" })
    public static String getClipBoardString() throws InterruptedException {
        PasteBoard.result = "";
        Log.d("UniPasteBoard", "Begin");
        final Activity currentActivity = UnityPlayer.currentActivity;
        final Runnable runnable = new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT < 11) {
                    PasteBoard.result = ((ClipboardManager)currentActivity.getSystemService("clipboard")).getText().toString();
                }
                else {
                    final android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager)currentActivity.getSystemService("clipboard");
                    currentActivity.getContentResolver();
                    final ClipData primaryClip = clipboardManager.getPrimaryClip();
                    if (primaryClip != null) {
                        PasteBoard.result = PasteBoard.coerceToText((Context)currentActivity, primaryClip.getItemAt(0)).toString();
                    }
                }
                synchronized (this) {
                    this.notify();
                }
            }
        };
        synchronized (runnable) {
            currentActivity.runOnUiThread((Runnable)runnable);
            runnable.wait();
            return PasteBoard.result.toString();
        }
    }

    public static void setClipBoardString(final String s) {
        Log.d("UniPasteBoard", "Copy Begin");
        final Activity currentActivity = UnityPlayer.currentActivity;
        currentActivity.runOnUiThread((Runnable)new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= 11) {
                    Log.d("UniPasteBoard", "Miao>11");
                    final android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager)currentActivity.getSystemService("clipboard");
                    if (clipboardManager != null) {
                        clipboardManager.setPrimaryClip(ClipData.newPlainText((CharSequence)"", (CharSequence)s));
                        Log.d("UniPasteBoard", "Copy OK");
                    }
                }
                else {
                    final ClipboardManager clipboardManager2 = (ClipboardManager)currentActivity.getSystemService("clipboard");
                    if (clipboardManager2 != null) {
                        clipboardManager2.setText((CharSequence)s);
                    }
                }
            }
        });
    }
}
